using DG.Tweening;
using DG.Tweening.Core;
using Sirenix.OdinInspector;
using UnityEngine;
using Utils.UGUI.Effect;

namespace WorkFlow.TweenGo
{
    [RequireComponent(typeof(UIGradient))]
    [ExecuteAlways]
    public class UIGradientTween : TweenGoBase<UIGradient,float>
    {
        public GradientColor startColor;
        public GradientColor endColor;
        
        [Range(0,1f)] 
#if UNITY_EDITOR
        [OnValueChanged("SetColor")] 
#endif
        public float currentValue = 0f;
        private void SetColor()
        {
            Target.gradientColor = GradientColor.Lerp(startColor, endColor, currentValue);
            Target.ForceUpdate();
        }

        protected override Tweener CreateTween(DOGetter<float> startValueGetter, DOSetter<float> setter, float endValue, float duration)
        {
            return DOTween.To(startValueGetter, SetValue, endValue, duration);
        }

        protected override float CurrentValue()
        {
            return currentValue;
        }

        protected override void SetValue(float value)
        {
            currentValue = value;
            SetColor();
            
        }
    }
}
